<%--

<!------------------------------------------------------------------------------
 - Copyright 2006 CORE Solutions Limited
 - All rights reserved.
 - PROPRIETARY AND CONFIDENTIAL INFORMATION.
 - Use is subject to license terms.
 -
 - FUNCTION ID      :   REMARK
 - AUTHOR           :   Ric Yik 
 - DATE CREATE      :   2006/01/05
 - DESCRIPTION      :   a CHILD TAB JSP file for the function, REMARK
 -                  :   
 -                  :   
 -                  :   
 -
 - MODIFICATION HISTORY:
 - DATE         AUTHOR          VERSION NO.         COMMENT
 - -----------  --------------  ------------------  -------------------
 - 2006/01/05   Ric Yik         1.0                 source is generated.
 -
 -
 -
------------------------------------------------------------------------------->

--%>
<%@ include file="/jsp/com/erp/app/common/jsp/directives_include.jsp"%>

<%@ page import="com.erp.app.setup.remark.vo.RemarkDtlVo"%>
<%@ page import="com.erp.app.setup.remark.web.RemarkMaintenanceAction"%>
<%@ page import="com.erp.app.setup.remark.web.RemarkMaintenanceForm"%>
<%@ page import="com.erp.app.setup.remark.web.RemarkDtlRow"%>
<%@ page import="com.erp.app.common.util.ProjectCommonUtil"%>

<%@ include file="/jsp/com/erp/app/common/jsp/html_include.jsp"%>

<jsp:useBean id="remarkMaintenanceForm" scope="session" type="com.erp.app.setup.remark.web.RemarkMaintenanceForm" />
<script language="JavaScript">

var lastCheckedIndex = -1;

function toGenericYN(yes) {
	return (yes) ? '<%=ProjectConstants.GENERIC_YES%>' : '<%=ProjectConstants.GENERIC_NO%>';
}

function doDtlIsDefault(checkBox, currentIndex) {
	var dtlIsDefault = document.forms[0].dtlIsDefault;
	var dtlIsDefaultHidden = document.forms[0].dtlIsDefaultHidden;
	if (lastCheckedIndex >= 0 && checkBox.checked) {
		var lastCheckBox = dtlIsDefaultHidden[lastCheckedIndex];
		lastCheckBox.checked = false;
		dtlIsDefault[lastCheckedIndex].value = toGenericYN(lastCheckBox.checked);
	}
	lastCheckedIndex = (checkBox.checked) ? currentIndex : -1;
	dtlIsDefault[currentIndex].value = toGenericYN(checkBox.checked);
}

</script>
<%
ArrayList remarkDtlList = remarkMaintenanceForm.getMultiRows(RemarkMaintenanceAction.TAB_IDX_DTL);
pageContext.setAttribute("remarkDtlList", remarkDtlList);
%>

<chtml:button form="remarkMaintenanceForm" pageEvent="<%=RemarkMaintenanceAction.ACTION_ADD_DTL%>" styleClass="button1"/>

<!-- MUST use the following to mark as mandatory field inputs-->
<!--<bean:message key="label.general.mandatory.field"/>-->

<%
rowReadOnly = false;
TableSchema[] childTsArray = remarkMaintenanceForm.getChildTs();
TableSchema childTs = childTsArray[RemarkMaintenanceAction.TAB_IDX_DTL];
%>

<table class="table_short_grid">

	<tr class="grid_header">
		<td class="grid_header" nowrap></td>
		<td class="grid_header" nowrap>
			<html:text useExtensions="true" uiType="label" childTsIndex="current" name="remarkMaintenanceForm" property="remarkDtlCode"/>
		</td>
		<td class="grid_header" nowrap>
			<html:text useExtensions="true" uiType="label" childTsIndex="current" name="remarkMaintenanceForm" property="dtlStatus"/>
		</td>
		<td class="grid_header" nowrap>
			<html:text useExtensions="true" uiType="label" childTsIndex="current" name="remarkMaintenanceForm" property="dtlIsDefault"/>
		</td>
		<td class="grid_header" nowrap>
			<html:text useExtensions="true" uiType="label" childTsIndex="current" name="remarkMaintenanceForm" property="dtlRemark"/>
		</td>
	</tr>
	<% int rowIndex = 0; %>
	<logic:iterate id="remarkDtlRow" name="remarkDtlList" indexId="idx">

	<%
		RemarkDtlRow row = (RemarkDtlRow) remarkDtlRow;
	%>

	<% if((row != null) && (CommonUtil.isEmpty(row.getIsDelete()))) {%>

	<tr <%=(idx.intValue() % 2 == 0) ? "class='grid_result1'" : "class='grid_result2'"%>>
		<%boolean isDelete = !ProjectCommonUtil.isEmpty(row.getIsDelete());%>
		<td nowrap><%
		if (!isDelete) {
			%><chtml:button form="remarkMaintenanceForm" pageEvent="<%=RemarkMaintenanceAction.ACTION_DEL_DTL%>" pageEventSrc="<%=String.valueOf(idx)%>" styleClass="button1" disabled="<%=String.valueOf(rowReadOnly)%>"/><%
		} else {
			%><img src="images/deleted.gif" width=15 height=15 border=0><html:hidden property="isDelete" value="<%=row.getIdx()%>" /><%
		}
		%></td>
		<td nowrap>
			<logic:equal name="remarkDtlRow" property="rowModeCreate" value="true"><%
			colSize = String.valueOf(childTs.getColSizeByObjectId("LBL_DTL_REMARK_DTL_CODE"));
			displaySize = String.valueOf(childTs.getDisplaySizeByObjectId("LBL_DTL_REMARK_DTL_CODE"));
			%><html:text property="remarkDtlCode" styleClass="textbox1" readonly="<%=rowReadOnly%>" maxlength="<%=displaySize%>" size="<%=colSize%>" value="<%=CommonUtil.nullToString(row.getRemarkDtlCode())%>"/>
			</logic:equal>
			<logic:notEqual name="remarkDtlRow" property="rowModeCreate" value="true">
				<bean:write name="remarkDtlRow" property="remarkDtlCode" filter="true"/>
				<html:hidden property="remarkDtlCode" value="<%=CommonUtil.nullToString(row.getRemarkDtlCode())%>" />
			</logic:notEqual>
		</td>
		<td nowrap>
			<select name="dtlStatus" <%=formReadOnly ? "disabled=\"true\"" : ""%> class="selectBox1">
				<%where = "(TYPE = '" + ProjectConstants.CONSTANT_TYPE_ACT_INACT + "' OR CONSTANT_CODE = '" + row.getDtlStatus() + "')";%>
				<chtml:options table="T_SYS_CONSTANTS"
				valuecolumn="CONSTANT_CODE"
				textcolumn="CONSTANT_NAME"
				where= "<%=where%>"
				order="ORDER_SEQ"
				selected="<%=row.getDtlStatus()%>" />
			</select>
		</td>
		<td nowrap><%
			colSize = String.valueOf(childTs.getColSizeByObjectId("LBL_DTL_IS_DEFAULT"));
			displaySize = String.valueOf(childTs.getDisplaySizeByObjectId("LBL_DTL_IS_DEFAULT"));
			%>
			<input type="checkbox" name="dtlIsDefaultHidden" <%= (row.isDtlDefault()) ? "checked": "" %> onclick="javascript:doDtlIsDefault(this, <%=rowIndex%>);"/>
			<html:hidden property="dtlIsDefault" value="<%= CommonUtil.nullToString(row.getDtlIsDefault()) %>" />
			<%
	    if (row.isDtlDefault()) {
	    	%><script language="JavaScript">lastCheckedIndex = <%=rowIndex%>;</script><%
			}
	    ++rowIndex;
		%></td>
		<td nowrap>
			<%
			textAreaCols = String.valueOf(childTs.getTextAreaColSizeByObjectId("LBL_DTL_REMARK"));
			textAreaRows = String.valueOf(childTs.getTextAreaRowSizeByObjectId("LBL_DTL_REMARK"));
			%>
			<html:textarea property="dtlRemark" styleClass="textarea1" readonly="<%=rowReadOnly%>" rows="<%=textAreaRows%>" cols="<%=textAreaCols%>" value="<%=CommonUtil.nullToString(row.getDtlRemark())%>"/>
			<input type="button" name="..." value="..." class="button1" onclick="<%="doSubmit('pEditDtlRemark', '" + idx.intValue() + "')"%>">
		</td>
	</tr>

	<%} else { %>

		<html:hidden property="isDelete" value="<%=row.getIdx()%>"/>

		<!--MUST INCLUDE hidden fields for all input objects such as textbox, textarea, check box, radio button, select box, etc.-->
		<html:hidden property="dtlRemark" value="<%=CommonUtil.nullToString(row.getDtlRemark())%>"/>
		<html:hidden property="dtlStatus" value="<%=CommonUtil.nullToString(row.getDtlStatus())%>"/>
		<html:hidden property="dtlIsDefault" value="<%=CommonUtil.nullToString(row.getDtlIsDefault())%>"/>

	<%} %>

		<html:hidden property="idx" value="<%=row.getIdx()%>" />
		<html:hidden property="rowMode"  value="<%=row.getRowMode()%>"/>

	</logic:iterate>

</table>

